home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
dscap.exe
/
DSCAP.C
next >
Wrap
C/C++ Source or Header
|
1993-06-08
|
13KB
|
504 lines
/****************************************************************************/
/* D S C A P . C */
/* */
/* Written By: Clint McVey */
/* Date: 05/01/93 */
/* Environment: BC 3.1 */
/* Description: DS Capture Example */
/* */
/* DSCAP is provided as is and carries no warranty */
/* whatsoever. Novell disclaims and excludes any and all implied */
/* warranties of merchantability, title and fitness for a particular */
/* purpose. Novell does not warrant that the software will satisfy */
/* your requirements or that the software is without defect or error */
/* or that operation of the software will be uninterrupted. You are */
/* using the software at your risk. The software is not a product */
/* of Novell, Inc. or any of subsidiaries. */
/* */
/* NOTE: */
/* Always reserve at least 8K of stack of DS functions. */
/* */
/****************************************************************************/
//
// At least 8K of stack should be reserved for DS functions.
//
unsigned _stklen = 8192;
#define NWDOS
#include <stdlib.h>
#include <dos.h>
#include <string.h>
#include <process.h>
#include <io.h>
#include <stdio.h>
#include <conio.h>
#include <memory.h>
#include <nwcalls.h>
#include <nwlocale.h>
#include <nwnet.h>
#include <nwerror.h>
NWCAPTURE_FLAGS1
captureFlags1;
NWCAPTURE_FLAGS2
captureFlags2;
NWCONN_HANDLE
defaultConnHandle;
NWLPT LPTDevice;
Buf_T NWFAR *Names = NULL;
Buf_T NWFAR *objectInfo = NULL;
Buf_T NWFAR *myFilter = NULL;
NWDSContextHandle
context;
void PrintOut( void );
void ResetToDefaults( void );
void CleanUp( int );
void main(int argc,char *argv[])
{
LCONV convert;
int NDSPresent;
int err,i,j;
Buf_T NWFAR
*Names = NULL;
Buf_T NWFAR
*objectInfo = NULL;
Buf_T NWFAR
*myFilter = NULL;
Filter_Cursor_T NWFAR
*filterCursor = NULL;
char serverName[MAX_DN_CHARS+2];
char attrName[] = {"Host Server"}; // Largest attr MAX_SCHEMA_NAME+2
NWDS_ITERATION
iterationHandle;
NWDS_NUM_OBJ
objectsSearched=0;
char objectName[MAX_DN_CHARS+2];
NWCCODE cCode;
NWDSCCODE cDSCode;
NWCONN_HANDLE connHandle;
NWOBJ_ID queueID;
NWLOCAL_MODE reserved1;
NWLOCAL_SCOPE reserved2;
NWCOUNT objectCount;
NWOBJECT_INFO *info;
NWCOUNT attrCount;
char cannonName[MAX_DN_CHARS+2];
NWCOUNT attrValCount;
void NWFAR *attrVal;
NWSYNTAX_ID syntaxID;
NWSIZE attrValSize;
if (argc > 1)
{
strcpy(objectName,argv[1]);
}
else
{
printf("\Invalid Number Of Arguments! Usage: DSCAP QUEUE");
putch(7);
exit(1);
}
cCode=NWCallsInit(NULL,NULL);
if(cCode != 0)
{
printf("\nFailure in NWCallsInit. Status: %04X Line: %d",cCode, __LINE__);
exit(1);
}
NWLsetlocale(LC_ALL, "");
NWLlocaleconv((LCONV NWFAR *)&convert);
NDSPresent = NWIsDSAuthenticated();
if (NDSPresent)
{
cCode = NWInitUnicodeTables(convert.country_id,
convert.code_page);
if (cCode)
{
printf("\nNWInitUnicodeTables: failed %04x", cCode);
exit(1);
}
}
else
{
printf("\nNot a DS connection...program terminating...");
exit(0);
}
//
// Create context and check for errors.
//
if((context = NWDSCreateContext()) == ERR_CONTEXT_CREATION)
{
printf("Could not create context. Must load on a 4.0 server.\n");
exit(0);
}
cDSCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &Names);
if(cDSCode)
{
printf("Error in NWDSAllocBuf: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode=NWDSInitBuf(context, DSV_SEARCH, Names);
if(cDSCode)
{
printf("Error in NWDSInitBuf: %d Line: %d\n", cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &myFilter);
if(cDSCode)
{
printf("Error in NWDSAllocBuf: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &objectInfo);
if(cDSCode)
{
printf("Error in NWDSAllocBuf: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSInitBuf(context,
DSV_SEARCH_FILTER,
objectInfo);
if(cDSCode)
{
printf("Error in NWDSInitBuf: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSInitBuf(context,
DSV_SEARCH_FILTER,
myFilter);
if(cDSCode)
{
printf("Error in NWDSInitBuf: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSAllocFilter(&filterCursor);
if(cDSCode)
{
NWDSFreeFilter(filterCursor,NULL);
printf("Error in NWDSAllocFilter: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_ANAME,
A_OBJECT_CLASS,
SYN_CLASS_NAME);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_EQ,
NULL,
NULL);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_AVAL,
A_QUEUE,
SYN_CLASS_NAME);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_AND,
NULL,
NULL);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_ANAME,
A_COMMON_NAME,
SYN_CI_STRING);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_EQ,
NULL,
NULL);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_AVAL,
(void *)objectName,
SYN_CI_STRING);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSAddFilterToken(filterCursor,
FTOK_END,
NULL,
NULL);
if(cDSCode)
{
printf("Error in NWDSAddFilterToken: %d Line: %d\n",cDSCode, __LINE__);
NWDSFreeFilter(filterCursor,NULL);
CleanUp(cDSCode);
}
cDSCode = NWDSPutFilter(context,
myFilter,
filterCursor,
NULL);
if(cDSCode)
{
printf("Error in NWDSPutFilter: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
cDSCode = NWDSPutAttrName(context, Names, attrName);
if(cDSCode)
{
printf("Error in NWDSPutAttrName: %d Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
iterationHandle=0xFFFFFFFF;
cDSCode = NWDSSearch(context,
DS_ROOT_NAME,
DS_SEARCH_SUBTREE,
FALSE,
myFilter,
DS_ATTRIBUTE_VALUES,
FALSE,
Names,
&iterationHandle,
1,
&objectsSearched,
objectInfo);
if(cDSCode)
{
printf("Error in NWDSSearch: %04X Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
if(iterationHandle != -1L)
{
cDSCode=NWDSCloseIteration(context,
iterationHandle,
DSV_CLOSE_ITERATION);
if(cDSCode)
{
printf("Error in NWDSCloseIteration: %04X Line: %d\n",cDSCode, __LINE__);
CleanUp(cDSCode);
}
}
cDSCode = NWDSGetObjectCount(context,
objectInfo,
&objectCount);
if(cDSCode)
{
printf ("Error in NWDSGetObjectCount: %d Line: %d\n", cCode, __LINE__);
CleanUp(cDSCode);
}
if(objectCount == 0)
{
printf("%s was not found in your default context.\n",objectName);
printf("\tPlease specify a valid queue name.\n");
putch(7);
cDSCode=0xFFFF;
CleanUp(cDSCode);
}
info = malloc(sizeof(Object_Info_T));
for(;objectCount>0; --objectCount)
{
cDSCode = NWDSGetObjectName(context,
objectInfo,
objectName,
&attrCount,
info);
if(cDSCode)
{
printf("Error in NWDSGetObjectName: %d Line: %d\n", cCode, __LINE__);
objectCount = -1;
attrCount = -1;
}
for (;attrCount>0; --attrCount)
{
cCode = NWDSGetAttrName(context,
objectInfo,
attrName,
&attrValCount,
&syntaxID);
if (cDSCode)
{
printf ("Error in NWDSGetAttrName: %d Line: %d\n",cCode,__LINE__);
break;
}
if (attrValCount > 1)
{
printf ("Invalid DS Connection. Line: %d\n",__LINE__);
break;
}
for (;attrValCount>0; --attrValCount)
{
cDSCode = NWDSComputeAttrValSize(context,
objectInfo,
syntaxID,
&attrValSize);
if(cDSCode)
{
printf ("Error in NWDSComputeAttrValSize: %d Line: %d\n",cCode,__LINE__);
break;
}
if((attrVal = malloc(attrValSize)) == NULL)
{
printf ("Unable to allocate memory for attribute value. Line: %d\n",cCode,__LINE__);
CleanUp(cDSCode);
}
cCode = NWDSGetAttrVal(context,
objectInfo,
syntaxID,
attrVal);
if(cDSCode)
{
printf ("Error in NWDSGetAttrVal: %d Line: %d\n",cCode,__LINE__);
free(attrVal);
break;
}
strcpy(serverName,attrVal);
free(attrVal);
}
}
}
//
// CleanUp DS Resources, but don't terminate
//
CleanUp(0);
//
// Extract Bindery "Style" Name
//
for(i=0,j=0;i<strlen(serverName);i++)
{
if(serverName[i] == '.')
{
if(i == 0)
{
if(serverName[i+3] == '=')
i+=4;
else
i++;
continue;
}
else
{
serverName[j] = NULL;
break;
}
}
serverName[j] = serverName[i];
if(serverName[i] == NULL) break;
j++;
}
cCode=NWAttachToFileServer(serverName,0,&connHandle);
if((cCode != 0) && (cCode != 0x8800))
{
printf("Unable to attach to %s. Status: %04X Line: %d\n",serverName,cCode,__LINE__);
NWDSFreeContext(context);
exit(1);
}
cDSCode=NWDSMapNameToID(context,connHandle,objectName,&queueID);
if(cDSCode)
{
printf("Error in NWDSMapNameToID. Status: %d Line: %d\n",cDSCode,__LINE__);
NWDSFreeContext(context);
putch(7);
exit(1);
}
NWDSFreeContext(context);
LPTDevice=0x01;
cCode=NWCancelCapture(LPTDevice);
if((cCode != 0) && (cCode != 0x884C))
{
printf("\nUnable to cancel capture. Status: %04X Line: %d",cCode,__LINE__);
exit(1);
}
cCode=NWStartQueueCapture(connHandle,LPTDevice,queueID,objectName);
if(cCode != 0)
{
printf("\nError starting queue capture. Status = %04X",cCode);
exit(1);
}
cCode=NWGetCaptureFlags(LPTDevice,&captureFlags1,&captureFlags2);
captureFlags1.numCopies=0x05;
captureFlags1.flushCaptureTimeout=(36);
captureFlags1.printFlags += 0x10; /* Notify When Done */
strcpy(captureFlags1.bannerText,"DS Capture!");
cCode=NWSetCaptureFlags(connHandle,LPTDevice,&captureFlags1);
if(cCode != 0)
{
printf("Error Setting Capture Flags. Status: %04X Line: %d\n",cCode,__LINE__);
exit(1);
}
PrintOut();
cCode=NWEndCapture(LPTDevice);
if(cCode != 0)
{
printf("Error in NWEndCapture. Status: %04X Line: %d\n",cCode,__LINE__);
exit(1);
}
printf("Successfully sent print data to %s.\n",objectName);
exit(0);
}
void PrintOut( void )
{
fprintf(stdprn,"This is a printer test");
fflush(stdprn);
}
void CleanUp ( int cDSCode )
{
if( Names )
NWDSFreeBuf(Names);
if( objectInfo )
NWDSFreeBuf(objectInfo);
if( myFilter )
NWDSFreeBuf(myFilter);
if(cDSCode)
{
NWDSFreeContext(context);
exit(1);
}
}